package tas.co.in.controller.roleAuthInfo;

import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import tas.co.in.dao.roleAuthInfo.roleAuthInfo;
import tas.co.in.domain.roleAuthInfo.roleAuthInfoBean;

public class roleAuthInfoController extends MultiActionController 
{
	private roleAuthInfo roleAuthInfo;

	public void setRoleAuthInfo(roleAuthInfo roleAuthInfo) 
	{
		this.roleAuthInfo = roleAuthInfo;
	}
	
	public ModelAndView getRoleAuthority(HttpServletRequest request, HttpServletResponse response)
	{
		List<roleAuthInfoBean> resultObject = roleAuthInfo.getRoleAuthority();
		return new ModelAndView("sharedJSP/groupCodeRecords", "resultObject", resultObject);
	}
	
	public ModelAndView getRoleDesc(HttpServletRequest request, HttpServletResponse response)
	{
		roleAuthInfoBean bean = new roleAuthInfoBean();
		bean.setCode(request.getParameter("code"));
		List<roleAuthInfo> resultObject = roleAuthInfo.getRoleDesc(bean);
		System.out.println(resultObject.size());
		return new ModelAndView("sharedJSP/groupCodeRecords", "resultObject", resultObject);
	}
	
	public ModelAndView approveRole(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		
		StringTokenizer items = new StringTokenizer(request.getParameter("selectdCustomers"), ",");
		roleAuthInfoBean bean = new roleAuthInfoBean();
		bean.setUserID(session.getAttribute("userId").toString());
		bean.setUserName(session.getAttribute("userName").toString());
		bean.setRoleID(session.getAttribute("roleId").toString());
		bean.setRoleCode(request.getParameter("roleCode"));
		boolean resultObject = roleAuthInfo.approveRole(items, bean);
		System.out.println(resultObject);
		return new ModelAndView("sharedJSP/BooleanResults","resultObject",resultObject);
	}
}
